<template>
  <div class="home-container">
    <Header></Header>
    <div class="content">
      <div class="sidebar">
        <ul>
          <li @click="selectSection('allBlogs')">全部博客</li>
          <li @click="selectSection('stars')">明星</li>
          <li @click="selectSection('pets')">宠物</li>
          <li @click="selectSection('anime')">二次元</li>
          <li @click="selectSection('lifestyle')">生活</li>
          <li @click="selectSection('food')">美食</li>
        </ul>
      </div>
      <div class="blog-summary">
        <div v-if="currentContent === 'allBlogs'">
          <BlogList></BlogList> 
        </div>
        <div v-else-if="currentContent === 'stars'">
          <StarBlog></StarBlog>
        </div>
        <div v-else-if="currentContent === 'pets'">
          <PatBlog></PatBlog>
        </div>
        <div v-else-if="currentContent === 'anime'">
          <MBlog></MBlog>
        </div>
        <div v-else-if="currentContent === 'lifestyle'">
          <LifeBlog></LifeBlog>
        </div>
        <div v-else-if="currentContent === 'food'">
          <MealBlog></MealBlog>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import { ref, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import BlogList from './BlogList.vue';
import Header from './Header.vue';
import StarBlog from './StarBlog.vue';
import PatBlog from './PatBlog .vue';
import MBlog from './MBlog.vue';
import LifeBlog from './LifeBlog.vue';
import MealBlog from './MealBlog.vue';

const router = useRouter();
const currentSection = ref('home'); 
const currentContent = ref('allBlogs'); 

// 选择左侧导航栏的内容
const selectSection = (section) => {
  currentContent.value = section; // 更新当前内容
}

// 在组件挂载时，设置当前页面
onMounted(() => {
  currentSection.value = router.currentRoute.value.name.toLowerCase(); // 根据当前路由设置选中状态
});
</script>

<style scoped>
.home-container {


  padding: 20px;
  background-color: #f9f9f9;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid #ccc;
  margin-bottom: 20px;
}

.top-nav {
  margin-bottom: 20px; /* 上方导航栏与内容之间的间距 */
}

.top-nav ul {
  list-style-type: none; /* 移除列表样式 */
  padding: 0; /* 移除内边距 */
  display: flex; /* 水平排列 */
}

.top-nav li {
  margin-right: 20px; /* 每个导航项之间的间距 */
  cursor: pointer; /* 鼠标悬停时显示为指针 */
  color: black; /* 默认颜色 */
}

.top-nav li.active {
  color: blue; /* 选中时的颜色 */
}
.content {
  display: flex; /* 使用 flexbox 布局 */
}
.sidebar {
  width: 100px; /* 设置侧边栏宽度 */
  height:280px;
  background-color: #f0f0f0; /* 侧边栏背景颜色 */
  padding: 20px;
}


.sidebar h2 {
  margin: 0 0 10px; /* 标题的 margin */
}

.sidebar ul {
  text-align: center;
  list-style-type: none; /* 移除列表样式 */
  padding: 0; /* 移除内边距 */
}

.sidebar li {
  cursor: pointer; /* 鼠标悬停时显示为指针 */
  padding: 10px; /* 添加内边距 */
  transition: background-color 0.3s; /* 添加过渡效果 */
}

.sidebar li:hover {
  background-color: #e0e0e0; /* 悬停时的背景颜色 */
}
.blog-summary {
  flex-grow: 1;
  padding: 20px; 
  background-color: #fff; 
  border: 1px solid #ccc; 
  border-radius: 5px; 
}
</style>